package tech.aistar.util;

import com.aliyuncs.CommonRequest;
import com.aliyuncs.CommonResponse;
import com.aliyuncs.DefaultAcsClient;
import com.aliyuncs.IAcsClient;
import com.aliyuncs.exceptions.ClientException;
import com.aliyuncs.exceptions.ServerException;
import com.aliyuncs.http.MethodType;
import com.aliyuncs.http.ProtocolType;
import com.aliyuncs.profile.DefaultProfile;

/* @author Ace
 * @version 1.0
 * @descriiption:本类用来演示:
 * @date 2019/10/9 0009.
 */
public class SmsService {

    public static void send(String phone,String key){
//第二个参数为自己独有的accessKeyid，第三个参数为自己独有的accessKeySecret
        DefaultProfile profile = DefaultProfile.getProfile("cn-hangzhou",
                "LTAI4Fvz9sQhKHGdxYtg7Nyf","XMu8JP34qCEi5JMewIogCzCQhNCfxi");
        IAcsClient client = new DefaultAcsClient(profile);
        CommonRequest request = new CommonRequest();//组装请求对象
//        request.setProtocol(ProtocolType.HTTPS);
        request.setMethod(MethodType.POST);//设置post提交
        request.setDomain("dysmsapi.aliyuncs.com");//短信API产品域名（接口地址固定，无需修改）
        request.setVersion("2017-05-25");
        request.setAction("SendSms");
        request.putQueryParameter("RegionId", "cn-hangzhou");
        request.putQueryParameter("PhoneNumbers", phone);
        request.putQueryParameter("SignName", "毕业设计宠物网站的注册");//短信签名
        request.putQueryParameter("TemplateCode", "SMS_175070091");
        request.putQueryParameter("TemplateParam", "{code:"+key+"}");
        System.out.println(phone);
        try {
            CommonResponse response = client.getCommonResponse(request);
            System.out.println(response.getData());
        } catch (ServerException e) {
            e.printStackTrace();
        } catch (ClientException e) {
            e.printStackTrace();
        }
    }
//    public static void main(String []args){
//
//        SmsService.send("18862635790","522126");
//
//    }
//public static void main(String []args) {
//    StringBuffer stringBuffer = new StringBuffer();
//    for (int x = 0; x <= 5; x++) {
//        int random = (int) (Math.random() * (10 - 1));
//        stringBuffer.append(random);
//    }
//    String code = stringBuffer.toString();
//    System.out.println(code);
//}
}
